package com.lx.interceptor;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器
 *
 * @author 段誉
 * @create 2019-03-21 9:03
 */
public class MyHandlerInterceptor1 extends HandlerInterceptorAdapter {
  /**
   * 进入处理器之前
   * @param request
   * @param response
   * @param handler
   * @return
   * @throws Exception
   */
  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                           Object handler) throws Exception {
    System.out.println("--------------------------MyHandlerInterceptor1.preHandle");
    return true;
  }

  /**
   * 处理器执行完毕，页面渲染之前
   * @param request
   * @param response
   * @param handler
   * @param modelAndView
   * @throws Exception
   */
  @Override
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler
          , ModelAndView modelAndView) throws Exception {
    System.out.println("--------------------------MyHandlerInterceptor1.postHandle");
  }

  /**
   * 页面渲染完毕之后
   * @param request
   * @param response
   * @param handler
   * @param ex
   * @throws Exception
   */
  @Override
  public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
                              Object handler, Exception ex) throws Exception {
    System.out.println("--------------------------MyHandlerInterceptor1.afterCompletion");
  }
}
